package com.example.workassignback.serviceImpl;

import com.example.workassignback.Mapper.DoctorMapper;
import com.example.workassignback.POJO.Doctor;
import com.example.workassignback.POJO.Item;
import com.example.workassignback.serviceImpl.service.DoctorService;
import com.example.workassignback.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: Lai Wenhao
 * @Date: 2024/6/1 11:54
 **/
@Service
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private DoctorMapper doctorMapper;

    public Result getInfo(String id) {
        Map<String,Object> map=new HashMap<>();

        Doctor d=doctorMapper.getInfo(id);
        System.out.println("d = " + d);
        map.put("doctor",d);
        System.out.println("map.get(\"doctor\") = " + map.get("doctor"));
        List<Item> list=doctorMapper.getItemFromDoctorId( Integer.toString( d.getDId()));

        map.put("item",list);

        return Result.success(map);
    }

    public Result getPatient(String findType , String findKey){
//        System.out.println("findKey = " + findKey);
        if(findType.equals("cardId")){
            return Result.success(doctorMapper.getPainterByCardId(findKey));
        }else if(findType.equals("name")){
            return Result.success(doctorMapper.getPainterByName(findKey));
        }else{
            return Result.fail("参数错误");
        }
    }

    public Result GetBeginItemsByStatus(String uId){
        String dId=doctorMapper.getDoctorIdByUserId(uId);
        return Result.success(doctorMapper.GetBeginItemsByStatus(dId,"2"));
    }

    public Result modifyInfo(Doctor doctor){
        return Result.success(doctorMapper.modifyInfo(doctor));
    }
}
